package Gui;

import java.awt.Color;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

import javax.swing.JTextField;
import javax.swing.JComboBox;

import client.LibaryMain;
import javax.swing.ImageIcon;
/**
 * this class implements gui of extend lending 
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
public class FreezeSubscriber extends JPanel {
	private static JTextField textFieldSearch;
	private JTextField textField_1;
	private static JLabel lblId;
	private static JLabel lblName;
	private static JComboBox<String> comboBox;
	public FreezeSubscriber() {
	
		initcomponents();
	
	}
/**
 * initilizing the freeze window 
 */
	public void initcomponents()
	{
	setBackground(new Color(153, 204, 255));
	setSize(998,710);
	setLayout(null);
	
	final JPanel panel = new JPanel();
	panel.setBounds(123, 264, 670, 316);
	add(panel);
	panel.setLayout(null);
	panel.setVisible(false);
	
	JLabel lblSetStatusTo = new JLabel("Set status to:");
	lblSetStatusTo.setFont(new Font("Tahoma", Font.BOLD, 16));
	lblSetStatusTo.setBounds(12, 112, 123, 16);
	panel.add(lblSetStatusTo);
	
	JButton btnConfirm = new JButton("Confirm");
	btnConfirm.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent arg0) {
			
			freeze(arg0);
		}

		
		
	});
	btnConfirm.setFont(new Font("Tahoma", Font.BOLD, 14));
	btnConfirm.setBounds(515, 271, 132, 32);
	panel.add(btnConfirm);
	
	comboBox = new JComboBox();
	comboBox.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent arg0) {
			if (comboBox.getSelectedItem().toString().equals("UnFreeze"))
			{
				textField_1.enable(false);
			}
			
			if (comboBox.getSelectedItem().toString().equals("Freeze"))
			{
				textField_1.enable(true);
			}
		}
	});
	comboBox.setFont(new Font("Tahoma", Font.BOLD, 16));
	comboBox.setBounds(202, 112, 139, 25);
	panel.add(comboBox);
	

	JLabel lblSubscriberId = new JLabel("Subscriber ID:");
	lblSubscriberId.setFont(new Font("Tahoma", Font.BOLD, 16));
	lblSubscriberId.setBounds(12, 25, 119, 16);
	panel.add(lblSubscriberId);
	
	JLabel lblPeriodOfFreezing = new JLabel("Period of Freezing:");
	lblPeriodOfFreezing.setFont(new Font("Tahoma", Font.BOLD, 16));
	lblPeriodOfFreezing.setBounds(12, 148, 159, 20);
	panel.add(lblPeriodOfFreezing);
	
	textField_1 = new JTextField();
	textField_1.setFont(new Font("Tahoma", Font.BOLD, 16));
	textField_1.setBounds(202, 143, 139, 25);
	panel.add(textField_1);
	textField_1.setColumns(10);
	
	lblId = new JLabel("ID");
	lblId.setFont(new Font("Tahoma", Font.BOLD, 16));
	lblId.setBounds(202, 25, 56, 16);
	panel.add(lblId);
	
	lblName = new JLabel("Name");
	lblName.setFont(new Font("Tahoma", Font.BOLD, 16));
	lblName.setBounds(202, 55, 159, 16);
	panel.add(lblName);
	
	JLabel lblSubscriberName = new JLabel("Subscriber Name:");
	lblSubscriberName.setFont(new Font("Tahoma", Font.BOLD, 16));
	lblSubscriberName.setBounds(12, 54, 159, 16);
	panel.add(lblSubscriberName);
	comboBox.addItem("Freeze");
	comboBox.addItem("UnFreeze");
	
	
	JLabel lblFreezeSubscriber = new JLabel("Freeze Subscriber");
	lblFreezeSubscriber.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 26));
	lblFreezeSubscriber.setBounds(44, 28, 296, 57);
	add(lblFreezeSubscriber);
	
	JButton btnBack = new JButton("Back");
	btnBack.addActionListener(new ActionListener() {
		
		public void actionPerformed(ActionEvent e) {
			
			MainScreen.cardLayot.show(MainScreen.card, "DirectorWindow");
		}
	});
	btnBack.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 14));
	btnBack.setBounds(88, 625, 97, 25);
	add(btnBack);
	
	JButton btnLogout = new JButton("Logout");
	btnLogout.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 14));
	btnLogout.setBounds(748, 625, 97, 25);
	add(btnLogout);
	
	JLabel lblEnterSubscriberId = new JLabel("Enter Subscriber ID :");
	lblEnterSubscriberId.setFont(new Font("Tahoma", Font.BOLD, 16));
	lblEnterSubscriberId.setBounds(113, 184, 190, 21);
	add(lblEnterSubscriberId);
	
	textFieldSearch = new JTextField();
	textFieldSearch.setFont(new Font("Tahoma", Font.BOLD, 16));
	textFieldSearch.setBounds(313, 181, 156, 26);
	add(textFieldSearch);
	textFieldSearch.setColumns(10);
	
	JButton btnSearch = new JButton("Search");
	btnSearch.setFont(new Font("Tahoma", Font.BOLD, 14));
	btnSearch.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent arg0) {
			
			btnSearch(arg0);
			
		}

		
		
		private void btnSearch(ActionEvent arg0) {
			panel.setVisible(true);	
			String ID; 
			ID = textFieldSearch.getText();
			ArrayList<String> Arr=new ArrayList<String>();
	        Arr.add("SearchFreeze");
	        Arr.add(ID);
	        LibaryMain.chat.handleMessageFromGui(Arr);
	        
			
		}
	});
	
	
	

	
	
	btnSearch.setBounds(507, 175, 147, 39);
	add(btnSearch);
	
	JLabel label = new JLabel("");
	label.setIcon(new ImageIcon(FreezeSubscriber.class.getResource("/Gui/images/business_user_delete.png")));
	label.setBounds(743, -39, 358, 397);
	add(label);
	}
	
	protected void freeze(ActionEvent arg0) {
		
		String freeze = (String) comboBox.getSelectedItem();
		
		if (freeze.equals("Freeze"))
		{	
			if (textField_1.getText().equals(""))
			{
				JOptionPane.showMessageDialog(null,"Please enter Date",freeze, JOptionPane.INFORMATION_MESSAGE);

			}
				else {
				int id = Integer.parseInt(textFieldSearch.getText());
				int  date =Integer.parseInt(textField_1.getText());
				ArrayList Arr=new ArrayList();
		        Arr.add("finalfreez");
		        Arr.add(id);
		        Arr.add(freeze);
		        Arr.add(date);
		        LibaryMain.chat.handleMessageFromGui(Arr); 
		        	}
			
		}
		
		
		else {
			
			
			int id = Integer.parseInt(textFieldSearch.getText());
			ArrayList Arr=new ArrayList();
	        Arr.add("finalfreez");
	        Arr.add(id);
	        Arr.add(freeze);
	        LibaryMain.chat.handleMessageFromGui(Arr); 
			
			
			
			}
	
        
	}

	public static void viewfreeze(String[] str) {
		lblId.setText(str[1]);
		lblName.setText(str[2]);
			
	
}
	
}
